package org.ddd.book.infrastructure.rpc;

import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * SOA服务远程接口
 */
@FeignClient(fallback = SoaApi.SoaApiFailBack.class, name = "SoaApi", url = "http://localhost:8888/api")
public interface SoaApi {

    @Data
    @Accessors(chain = true)
    class UserInfo {
        private Long userId;
        private String userName;
        private String userAccount;
        private String sex;
        private Integer age;
    }

    @GetMapping("/{userId}")
    UserInfo findUser(@PathVariable Long userId);


    @Component
    @Slf4j
    class SoaApiFailBack implements SoaApi {

        @Override
        public UserInfo findUser(Long userId) {
            return new UserInfo().setUserId(userId).setUserAccount("FB" + System.currentTimeMillis()).setUserName("FB");
        }

    }
}
